package com.xbongbong.saas.script.modifyenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.dictionary.HasRedEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
 * 资金管理二期改造，修改两个字段，新增两个字段
 * 新增字段：
 * 坏账金额:坏账金额的变化由回款单的变化而变化
 * 开票金额
 * <p>
 * 修改字段：
 * 归属人-->由可见改为不可见，先还改为不可见，后期把字段回收
 * 支付方式-->由可见改为不可见，先还改为不可见，后期把字段回收
 *
 * @author chenshan
 * @version v1.0
 * @since 2019-11-25 14:54
 */
@Getter
public enum FundPayPlanScriptEnum {
	//资金管理处理合同新增修改字段
	HAS_RED(PayPlanEnum.HAS_RED,1),
	STATUS(PayPlanEnum.STATUS,1),
	BAD_AMOUNT(PayPlanEnum.BAD_AMOUNT,2),
	INVOICE_AMOUNT(PayPlanEnum.INVOICE_AMOUNT, 1),
	BELONGER(PayPlanEnum.BELONGER,2),
	PAYMENT_METHOD(PayPlanEnum.PAYMENT_METHOD,2),
	PAY_TYPE(PayPlanEnum.PAY_TYPE,1),
	FINISH_AMOUNT(PayPlanEnum.REAL_AMOUNT,1),
	UN_AMOUNT(PayPlanEnum.UN_AMOUNT,1),
	;
	/**
	 * 采购合同
	 */
	private PayPlanEnum payPlanEnum;
	/**
	 * 类型，1:修改，2:新增
	 */
	private Integer type;
	
	FundPayPlanScriptEnum(PayPlanEnum payPlanEnum, Integer type) {
		this.payPlanEnum = payPlanEnum;
		this.type = type;
	}
	
	public static List<FundPayPlanScriptEnum> getAllEnum() {
		List<FundPayPlanScriptEnum> list = new ArrayList<>();
		Collections.addAll(list, values());
		return list;
	}
	
	public static List<FundPayPlanScriptEnum> getEnumByType(Integer type) {
		List<FundPayPlanScriptEnum> list = new ArrayList<>();
		for ( FundPayPlanScriptEnum cache : values() ) {
			if ( Objects.equals(type, cache.getType()) ) {
				list.add(cache);
			}
		}
		return list;
	}
	/**
	 * 处理坏账金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2019-11-26 15:36
	 */
	public static void initAddBadAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("坏账金额");
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PayPlanEnum.BAD_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
		fieldAttrEntity.setShowAttrPermission(BasicConstant.ONE);
		fieldAttrEntity.setShowEditable(0);
	}
    
    /**
     * 初始化开票金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("开票金额");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PayPlanEnum.INVOICE_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
		fieldAttrEntity.setShowAttrPermission(BasicConstant.ONE);
		fieldAttrEntity.setShowEditable(0);
	}
	
	public static void initHasRed(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("是否有红冲付款单");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PayPlanEnum.HAS_RED.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setIsForbidden(0);
		fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(HasRedEnum.class, fieldAttrEntity.getFieldType()));
	}
	
	public static void initPayType(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setSetType(3);
		fieldAttrEntity.setRequired(0);
	}
	
	public static void initFinishAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setShowEditable(0);
	}
	
	public static void initUnAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setShowEditable(0);
	}
	
}
